package com.wanxi.controller.front;


import com.wanxi.domain.ResultModel;
import com.wanxi.domain.front.NewsModel;
import com.wanxi.service.front.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("front")
@RestController
@CrossOrigin(allowCredentials = "true", origins = "http://localhost:63342", allowedHeaders = "*")//允许跨域请求
public class NewsController {

    @Autowired
    private NewsService newsService ;

    /*查询前端新闻页面的所有新闻*/
    @GetMapping("newsFindAll")
    public List<NewsModel> findAll(int page,int limit){

        List<NewsModel> resultModel = newsService.findAll(page,limit);

        return resultModel;
    }

    /*查询所有新闻条数*/
    @GetMapping("newsSum")
    public int getNewsSum(){

        int resultModel = newsService.getCount();
        return resultModel;
    }

    /*获取某一类新闻的数量*/
    @GetMapping("newsTypeSum")
    public int getCountForTypeName(String typeName){

        int resultModel =  newsService.getTypeCount(typeName);

        return resultModel;
    }

    /*获取某一类的所有新闻*/
    @GetMapping("newsFindByCategory")
    public List<NewsModel>  findByType(int page,int limit,String typeName){


        List<NewsModel>  resultModel = newsService.findByType(page,limit,typeName);

        return resultModel;
    }
}
